#include "StdAfx.h"
#include ".\handler_cg_event.h"
#include <PacketStruct_CG.h>
#include <PacketStruct_DG.h>
#include "EventInventorySlotContainer.h"

Handler_CG_EVENT_IMPL( CG_EVENT_SELECT_SYN )
{
	MSG_CG_EVENT_SELECT_SYN * pMsg = (MSG_CG_EVENT_SELECT_SYN *)pRecvMsg;

	Player * pPlayer = PlayerManager::Instance()->FindPlayer( pMsg->m_dwKey );
	ASSERT( pPlayer );
	if( !pPlayer ) return ;
	if( !pPlayer->GetField() ) return;


	RC::eEVENT_RESULT rt = pPlayer->GetEventSlotContainer()->Open();
	if( rt == RC::RC_EVENT_SUCCESS )
	{
		MSG_DG_EVENT_SELECT_SYN msg;
		msg.m_UserGuid = pPlayer->GetUserGuid();
		pPlayer->SendToGameDBPServer( &msg, sizeof(msg) );
	}
	else
	{
		MSG_CG_EVENT_SELECT_NAK nmsg;
		nmsg.m_byErrorCode = rt;
		pPlayer->SendPacket( &nmsg, sizeof(nmsg) );
	}

}

Handler_CG_EVENT_IMPL( CG_EVENT_MOVE_ITEM_TO_INVEN_SYN )
{
	MSG_CG_EVENT_MOVE_ITEM_TO_INVEN_SYN * pMsg = (MSG_CG_EVENT_MOVE_ITEM_TO_INVEN_SYN *)pRecvMsg;

	Player * pPlayer = PlayerManager::Instance()->FindPlayer( pMsg->m_dwKey );
	ASSERT( pPlayer );
	if( !pPlayer ) return ;
	if( !pPlayer->GetField() ) return;

	MSG_DG_EVENT_UPDATE_SYN msg;
	RC::eEVENT_RESULT rt = pPlayer->GetEventSlotContainer()->MoveItemToInventory( pMsg->m_ItemPos, msg.m_ItemSeq );
	if( rt == RC::RC_EVENT_SUCCESS )
	{
		msg.m_UserGuid	= pPlayer->GetUserGuid();
		msg.m_ItemPos	= pMsg->m_ItemPos;
		pPlayer->SendToGameDBPServer( &msg, sizeof(msg) );
	}
	else
	{
		MSG_CG_EVENT_MOVE_ITEM_TO_INVEN_NAK nmsg;
		nmsg.m_byErrorCode = rt;
		pPlayer->SendPacket( &nmsg, sizeof(nmsg) );
	}
}

